package com.pixel.game.entity;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2;
import com.pixel.game.Utils.PositionUtils;

public class Bullet {
    private Vector2 position;
    private Vector2 direction;
    private float speed;
    private boolean active;

    public Bullet(Vector2 startPosition, Vector2 direction, float speed) {
        this.position = startPosition;
        this.direction = direction.nor(); // 规范化方向向量
        this.speed = speed;
        this.active = true;
    }

    public void update(float deltaTime) {
        if (!active) return;

        // 移动子弹
        position.x += direction.x * speed * deltaTime;
        position.y += direction.y * speed * deltaTime;

        // 检查是否超出边界（示例：屏幕边界）
        if (position.x < 0 || position.x > PositionUtils.getScreenWidth() || position.y < 0 || position.y > PositionUtils.getScreenHeight()) {
            active = false;
        }
    }

    public void draw(SpriteBatch batch) {
        if (!active) return;

        // 示例：绘制子弹，可以替换为你的纹理
        TextureRegion bulletTexture = new TextureRegion();
        batch.draw(bulletTexture, position.x, position.y);
    }

    public boolean isActive() {
        return active;
    }
}
